package leave.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class CalculateOT {

	public static int calculateOTHour(int signInTime, int signOutTime)
	{
		int otTime = 0;
        int workingTime = signOutTime-signInTime;
        otTime = workingTime - 9;
        if(otTime > 0)
        	return otTime;
        return 0;
	}
	
	public static int calculateOTHour(Date signInTime, Date signOutTime)
	{
		int otTime = 0;
		Calendar calSingIn = Calendar.getInstance();
		Calendar calSingOut = Calendar.getInstance();
		calSingIn.setTime(signInTime);
		calSingOut.setTime(signOutTime);
		long singInMillseconds = calSingIn.getTimeInMillis();
		long singOutMillseconds = calSingOut.getTimeInMillis();
		long diff = singOutMillseconds - singInMillseconds;
		long diffHours = diff / (60 * 60 * 1000);
		otTime = (int)diffHours - 9;
		if(otTime > 0)
			return otTime;
		return 0;
	}
	
	public static void main(String[] args)
	{
		try
		{
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			String signInTime = "2011/12/11 09:00:00";
			String signOutTime = "2011/12/11 20:00:00";
			System.out.println(calculateOTHour((Date)formatter.parse(signInTime), (Date)formatter.parse(signOutTime)));
		}
		catch(ParseException ex)
		{
			System.err.print(ex.getMessage());
		}
	}
}
